D3.js 框架:終極的互動圖形解決方案Plotly for R is an interactive, browser-based charting library built on the open source javascript graphing library, plotly.js. It works entirely locally, through the HTML widgets framework.
# install.packages("plotly")
library(plotly) # Load package
library(gapminder) # Load data
library(dplyr)
gapminder_2007 <- gapminder %>%
filter(year == 2007)
p <- plot_ly(data = gapminder_2007, x = ~gdpPercap, y = ~lifeExp) # Save plot as pp # Display plotplotly 函數plot_ly()plot_geo()layout()add_trace()style()p <- plot_ly(...) %>%
add_trace(...) %>%
add_layout(...) # Save plot as p
p # Display plotShiny is an R package that makes it easy to build interactive web apps straight from R. You can host standalone apps on a webpage or embed them in R Markdown documents or build dashboards. You can also extend your Shiny apps with CSS themes, htmlwidgets, and JavaScript actions.
ui.Rserver.Rui.Rlibrary(shiny)
shinyUI(
fluidPage(
titlePanel("My First Shiny App"),
sidebarLayout(
sidebarPanel(
checkboxGroupInput("continents",
"Select continents:",
c("Asia" = "Asia",
"Europe" = "Europe",
"Africa" = "Africa",
"Americas" = "Americas",
"Oceania" = "Oceania"),
selected = c("Asia", "Europe", "Africa", "Americas", "Oceania")
)
),
mainPanel(
plotOutput("scatterPlot")
)
)
)
)server.Rlibrary(shiny)
library(dplyr)
library(gapminder)
library(ggplot2)
# Define server logic required to draw a histogram
shinyServer(function(input, output) {
output$scatterPlot <- renderPlot({
selected_continents <- input$continents
gapminder_plot <- gapminder %>%
filter(year == 2007) %>%
filter(continent %in% selected_continents)
ggplot(gapminder_plot, aes(x = gdpPercap, y = lifeExp, colour = continent, size = pop)) +
geom_point()
})
})input$ 變數使用 reactive() 函數